﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace EPS.UI.Modules
{
    /// <summary>
    /// Interaction logic for DataPager.xaml
    /// </summary>
    public partial class DataPager : UserControl
    {

        public static readonly DependencyProperty RecordCountProperty = DependencyProperty.Register
        ("RecordCount", typeof(int), typeof(DataPager), new PropertyMetadata(
          null));

        public static readonly DependencyProperty PageSizeProperty = DependencyProperty.Register
        ("PageSize", typeof(int), typeof(DataPager), new PropertyMetadata(
          null));

        public static readonly DependencyProperty CurrentPageIndexProperty = DependencyProperty.Register
        ("CurrentPageIndex", typeof(int), typeof(DataPager), new PropertyMetadata(
          null));

        public static readonly DependencyProperty PageCountProperty = DependencyProperty.Register
        ("CurrentPageIndex", typeof(int), typeof(DataPager), new PropertyMetadata(
          null));

        public DataPager()
        {
            InitializeComponent();
        }


        public int RecordCount
        {
            get
            {
                return (int)GetValue(DataPager.RecordCountProperty);
            }
            set
            {
                SetValue(DataPager.RecordCountProperty, value);
            }
        }

        public int PageSize
        {
            get
            {
                return (int)GetValue(DataPager.PageSizeProperty);
            }
            set
            {
                SetValue(DataPager.PageSizeProperty, value);
            }
        }


        public int CurrentPageIndex
        {
            get
            {
                return (int)GetValue(DataPager.CurrentPageIndexProperty);
            }
            set
            {
                SetValue(DataPager.CurrentPageIndexProperty, value);
            }
        }

        public int PageCount
        {
            get
            {
                return (int)GetValue(DataPager.PageCountProperty);
            }
            set
            {
                SetValue(DataPager.PageCountProperty, value);
            }
        }

        private void UpdateState()
        {
            int pageCount = 0;
            if (PageSize > 0) pageCount = (int)Math.Ceiling((double)RecordCount / PageSize);
            lbSumPage.Content = string.Format("共{0}页", pageCount);
            lbSumPage.Tag = pageCount;
            lbSumRecord.Content = string.Format("共{0}页", RecordCount);
            lbSumRecord.Tag = RecordCount;
            lbPersentPage.Content = string.Format("当前第{0}页", CurrentPageIndex);
            lbPersentPage.Tag = CurrentPageIndex;
        }
    }
}
